package plochki;

//Simple algorithm,
//different from BaiIvan only in that it traverses the Figures with even indexes first
//then those with odd indexes
public class BaiGosho extends BaseWorker {

	public BaiGosho(String inputFile) {
		super(inputFile);
		
		this.name = "BaiGosho";
	}
	
	public BaiGosho(String[] inputFigures) {
		super(inputFigures);
		
		this.name = "BaiGosho";
	}

	//For each Figure if stuck, remove and place on a better spot
	//Traverse the figures in reverse order
	protected void nalepiPlochki() {
		Figura fig;
		int size = this.figuri.size();
		
		//Traverse even indexes
		for (int i = 0; i < size; i+=2) {

			fig = this.figuri.get(i);
			
			//If a figure is stuck with another figure
			if (this.getStuckLevel(fig)>0) {
				//remove from field
				this.otlepiPlochka(fig);
				
				//find a new place for the Figure, the closest possible
				this.findBestPlaceForFigure(fig);
			}
		}
		
		//Traverse odd indexes
		for (int i = 1; i < size; i+=2) {

			fig = this.figuri.get(i);
			
			//If a figure is stuck with another figure
			if (this.getStuckLevel(fig)>0) {
				//remove from field
				this.otlepiPlochka(fig);
				
				//find a new place for the Figure, the closest possible
				this.findBestPlaceForFigure(fig);
			}
		}
	}
}
